package 剑指offer;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Queue;

public class 栈的压入与弹出序列 {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Deque<Integer> deque=new ArrayDeque();
        int j=0;
        for (int i : pushed) {
            deque.push(i);
            while (j<popped.length && !deque.isEmpty() && deque.peek()==popped[j]){
                deque.pop();
                j++;
            }
        }
        return j==popped.length;
    }
}
